﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.OleDb;

public partial class webform1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //if (Session["login1"].ToString() != "yes")
        //{
        //    Response.Redirect("Webform2.aspx");
        //}
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string str = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\C#\考核九\k9.mdb";
        OleDbConnection myoc = new OleDbConnection();
        myoc.ConnectionString = str;
        myoc.Open();
        OleDbCommand myom = new OleDbCommand();
        string str1 = "select * from zym";
        myom.CommandText = str1;
        myom.Connection = myoc;
        OleDbDataReader myread = myom.ExecuteReader();
        List<string> zh = new List<string>();
        List<string> mm = new List<string>();
        while (myread.Read())
        {
            zh.Add((string)myread[1]);
            mm.Add((string)myread[2]);

        }
        for (int i = 0; i <= zh.Count - 1; i++)
        {
            if (TextBox1.Text == zh[i] && TextBox2.Text == mm[i])
            {
                Response.Write("登陆成功");
                //break;
                Session["login"] = "yes";
                Response.Redirect("Webform2.aspx");
                break;
            }
            if (i >= zh.Count - 1)
            {
                Response.Write("用户名或密码错误");
            }
        }
    }
}